package com.rrd.dw.mr.gzip.kafka;


import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.umeng.UmengCareerFeature;
import com.ucredit.babel.common.model.umeng.UmengCareerFeatureData;
import com.ucredit.babel.common.model.umeng.UmengCareerFeatureRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;
/**
 *友盟-职业特征
 *
 * @author rrz
 */


public class UmengCareerFeatureParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 友盟-职业特征
     *
     * @param model
     * @throws IOException
     * @throws InterruptedException
     * @return
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        UmengCareerFeatureRecord obj = (UmengCareerFeatureRecord)model;
        UmengCareerFeatureData data = obj.getData();
        UmengCareerFeature data1 = data.getData();

        StringBuilder sb = getBaseInfo(obj, successful);

        //信息
        sb.append(data.getMessage()).append(CRT001);
        //请求ID
        sb.append(data.getRequestId()).append(CRT001);
        //状态码
        sb.append(data.getCode()).append(CRT001);
        //输出评分
        sb.append(data1.getScore()).append(CRT001);
        //该事件下命中策略的标签值
        sb.append(data1.getTags()).append(CRT001);
        StringBuilder txSb = getBaseInfo(obj);

        key.set(getKey());
        val.set((sb.toString() + txSb).replace("\n","").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_youmeng_career_inc";
    }

    @Override
    public String getType() {
        return RecordType.UMENG_CAREER_FEATURE_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "友盟职业特征";
    }
}
